/**
 * Created by pc on 2017/3/30.
 */
import React from "react";
import Pagination from "./Pagination";
import "./css/homePage.css"
export default class UserTable extends React.Component{

    constructor(props){
        super(props);
        this.state={

            /*后台错误提示*/
            hint:"",
            //起始时间
            timeBefore:"",
            //结束时间
            timeAfter:"",
            //列表数组
            userCensusList:[],
            /*总共多少条*/
            total: 0,
        };
    }



    /*日期格式化*/
    dateFormat(time){
        if(time){
            let zero=(n)=>{
                return n = n>=0&&n<10 ? "0"+n : n;
            };
            let y = new Date(time).getFullYear();
            let m = new Date(time).getMonth()+1;
            let d = new Date(time).getDate();
            let h = new Date(time).getHours();
            let ms = new Date(time).getMinutes();

            return zero(y)+"-"+zero(m)+"-"+zero(d);
        }
    }


    addItem() {
        if(this.state.userCensusList.length == 0){
            //alert("获取到的数据为空！");
            return(
                <tr >
                    <td>
                        没有找到相关信息！
                    </td>
                </tr>
            );
        }

        return this.state.userCensusList.map((item, index) => {
            return (
                <tr key={index}>
                    <td>{this.dateFormat(item.dateTime)}</td>
                    <td>{item.userIncrease}</td>
                    <td>{item.userActive}</td>
                    <td>{item.userTotal}</td>
                    <td>{item.userIncreasePercent}%</td>
                </tr>
            )
        })
    }

    onSure(pageSize, pageNum) {
        // debugger
        this.props.userCensuByDate(pageSize, pageNum)

        // this.refs.priseId.state.text
    }

    render() {
        return (
            <div className="loan_rec">
                <div>
                    <table className="settle_rec_table recharge_recCom_table">
                        <thead>
                            <tr>
                                {
                                    ["日期","新增用户","活跃用户","累计用户","新用户占比"].map((item,index)=>
                                        <th key={index}>
                                            {item}
                                        </th>
                                    )
                                }
                            </tr>
                        </thead>

                        <tbody>
                            {
                                this.addItem()
                            }
                        </tbody>
                    </table>
                    {/*页码*/}
                    <Pagination eachSize={10} dataSize={this.state.total} onSure={this.onSure.bind(this)}
                                ref={'pagination'}/>

                </div>
            </div>
        )
    }



}